<template>
  <div>

    <el-dialog
      title="跟踪记录"
      :visible.sync="dialogVisible"
      width="60%"
     >
      <avue-crud
        v-model="form"
        :search.sync="searchForm"
        :page.sync="page"
        :data="tableData"
        :table-loading="tableLoading"
        :option="tableOption"
        @on-load="getList"
        @search-change="searchChange"
        @refresh-change="refreshChange"
        @size-change="sizeChange"
        @current-change="currentChange"
        @row-update="handleUpdate"
        @row-save="handleSave"
        @row-del="rowDel"
      >
      </avue-crud>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
  </span>
    </el-dialog>
  </div>


</template>

<script>
import tableMixins from "@/mixins/tableMixin.vue"
export default {
  mixins: [tableMixins],
  name: "trackingRecord",
  data(){
    return{
      dialogVisible:false,
      form: {},
      //访问接口前缀
      url: "yuanjiu.testnew/tn-task-list",
      searchForm: {},
      // 表格参数
      tableOption: {
        border: true,
        labelWidth:120,
        index: false,
        indexLabel: '序号',
        indexWidth: 50,
        stripe: true,
        align: 'center',
        searchMenuSpan: 8,
        searchLabelWidth: 100,
        calcHeight: 300,
        dialogWidth: 900,
        menuWidth: 200,
        menu: true,
        menuAlign: 'center',
        refreshBtn: false,
        columnBtn: false,
        searchShowBtn: false,
        addBtn: true,
        selection: false,
        rowKey: "id",
        emptyBtn: true,
        editBtn: true,
        viewBtn: true,
        delBtn: false,
        emptyBtnText: "重置",
        editBtnText: "修改",
        maxHeight: 645000,
        searchSize: "medium",
        column: [
          {
            prop: 'flowTypeCode',
            label: '跟踪类型',
            type: "select",
            dicUrl: '/yuanjiu.testnew/yj-config/getConfigByCode?itmCode=FLOW_TYPE',
            props: {
              label: "itmName",
              value: "itmVal",
              res: "result"
            }
          },
          {
            prop: 'resultCode',
            label: '跟踪结果',
            type: "select",
            dicUrl: '/yuanjiu.testnew/yj-config/getConfigByCode?itmCode=FLOW_RSLT',
            props: {
              label: "itmName",
              value: "itmVal",
              res: "result"
            }
          },
          {
            prop: 'priorLvl',
            label: '优先级',
            type: "select",
            hide:true,
            props: {
              label: 'name',
              value: 'code'
            },
            dicData: [
              {
                name: '低',
                code: 1
              }, {
                name: '中',
                code: 2
              }, {
                name: '高',
                code: 3
              }]
          },
          {
            prop: 'result',
            label: '跟踪记录',
            type:"textarea",
            span:24
          },
          {
            prop: 'flowTime',
            label: '跟踪时间',
            editDisplay:false ,addDisplay:false ,
          },
          {
            prop: 'mailAddr',
            label: '跟踪人',
            editDisplay:false ,addDisplay:false ,
          },
          {
            prop: 'duration',
            label: '跟踪时长',
            type: "number"
          },
          {
            prop: 'nextFlowTime',
            label: '下次跟踪时间',
            type: "date",
            format:'yyyy-MM-dd',
            valueFormat:'yyyy-MM-dd',
          },
        ]
      },
      listUrl: 'pageTnMail',
      delUrl: "deleteList",
      updateUrl:"insertOrUpdate",
      delIdList: [],
    }
  },
  methods:{
    openDialog(stuId){
      this.dialogVisible =true
      this.stuId = stuId
    },
    // 获取数据
    /**
     * 获取列表数据
     */
    getList() {
      this.tableLoading = true;
      let query = Object.assign({}, this.searchForm, this.page,this.search);
      query.current = this.page.currentPage
      query.size = this.page.pageSize
      query.stuId = this.stuId
      this.$httpService.post('/yuanjiu.testnew/tn-task-list/pageTnFlowRecordByStuId',query).then(res => {
        this.tableData = res.records
        this.page.total = res.total;
        this.tableLoading = false
      })
    },

    /**
     * 新增保存
     * @param row 行数据
     * @param done 完成回调
     * @param loading 加载回调
     */
    handleSave: function (row, done, loading) {
      row.stuId = this.stuId
      this.$httpService.post("/" + this.url + "/"+this.updateUrl, row).then(res => {
        this.$message.success('新增成功');
        this.getList();
        done();
        loading();
      }).catch(res=>{
        loading();
      })
    },


    /**
     * 修改保存
     * @param row 行数据
     * @param index 行索引
     * @param done 完成回调toggleSelection
     * @param loading 加载回调
     */
    handleUpdate: function (row, index, done, loading) {
      row.stuId = this.stuId
      this.$httpService.post("/" + this.url + "/"+this.updateUrl, row).then(res => {
        this.$message.success('修改成功');
        this.getList();
        done();
        loading();
      }).catch(res=>{
        loading();
      })
    },

  }
}
</script>

<style scoped>

</style>
